cc.Class({
    extends: cc.Component,

    properties: {
        triangle: cc.Node,
        comboLabel: cc.Label,
        dropDown: cc.Node,
        LayoutNode: cc.Node,
        contentNode: cc.Node,
        itemPrefab: cc.Prefab
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        // 是否已经下拉
        this.isDropDown = false;

        // 下拉框选项内容
        this.itemArray = ['4', '5', '6'];
        this.initItems();
    },

    // 点击按钮触发下拉框
    comboboxClicked() {
        // 旋转三角形
        this.rotateTriangle();
        // 下拉框显示与隐藏
        this.showHideDropDownBox();
        if (!this.isDropDown) {
            this.isDropDown = true;
        }
        else {
            this.isDropDown = false;
        }
    },

    // 旋转三角形（正值为顺时针，负值为逆时针）
    rotateTriangle() {
        if (!this.isDropDown) {
            let rotateAction = cc.rotateTo(0.5, -90).easing(cc.easeCubicActionOut());
            this.triangle.runAction(rotateAction);
        }
        else {
            let rotateAction = cc.rotateTo(0.5, 0).easing(cc.easeCubicActionOut());
            this.triangle.runAction(rotateAction);
        }
    },

    // 下拉框显示与隐藏
    showHideDropDownBox() {
        if (!this.isDropDown) {
            this.dropDown.active = true;
        }
        else {
            this.dropDown.active = false;
        }
    },

    // 创建下拉框选项数组
    initItems() {
        // 根据数组初始化下拉框中的各个选项内容
        let totalHeight = 0;
        for (let i = 0; i < this.itemArray.length; i++) {
            let item = cc.instantiate(this.itemPrefab);
            item.children[0].getComponent(cc.Label).string = this.itemArray[i];
            item.getComponent('Item').initComBo(this);
            this.LayoutNode.addChild(item);
            totalHeight += item.height;
        }

        // 设置content高度
        if (totalHeight > this.contentNode.height) {
            this.contentNode.height = totalHeight;
        }
    },

    start() {

    },

    // update (dt) {},
});
